#include <AT89X52.h>
#include <STDIO.H>
extern unsigned char Tcount0;
unsigned char x=0,y=0;

unsigned char InputScan()
{

	unsigned char  Key=0x10;
	unsigned char Keydata=0;
	P2=0xf0;
	Keydata=P2;
	Keydata=Keydata&0xf0;
	if(	Keydata==0xf0)
	{
	}
	else
	{
	    if(	Keydata==0xe0)
 	    {
	        x=0;
  	    }
	    else
	    if(	Keydata==0xd0) 
	    {
	        x=1;
	    }
	    else
	    if(	Keydata==0xb0)
	    {
	        x=2;
	    }
	    else
	    if(	Keydata==0x70)
	    {
	        x=3;
	    }
	    P2=0x0f;
		Keydata=P2;
	    Keydata=Keydata&0x0f;
	    if(Keydata==0x0e)
	    {
	        y=3;
	    }
	    else
	    if(Keydata==0x0d)
	    {
	        y=2;
	    }
	    else
	    if(Keydata==0x0b)
	    {
	        y=1;
	    }
	    else
	    if(Keydata==0x07)
	    {
	        y=0;
	    }
        Key=4*y+x;
    }
	return(Key); 
}

int num[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void InputTest()
{
	unsigned char K;
	while(1)
	{
	    K=InputScan();
	    P1=0x7f;
	    if(K<0x10)
	    {
  	        P0=num[K];
	    }
	}
}
